package sh.action;

import com.opensymphony.xwork2.ActionSupport;
import lombok.Data;
import sh.model.Book;
import sh.service.BookService;
import sh.service.impl.BookServiceImpl;
import sh.util.ActionResultConst;

import java.util.List;

/**
 * @author lqq
 * @date 2019/1/18
 */
@Data
public class BookAction extends ActionSupport {

    private Book book;

    private List<Book> books;

    @Override
    public String execute() throws Exception {
        return super.execute();
    }


    // 已经有add 方法，并且配了 action的name属性，为什么还是走的默认方法
    // action 的method 属性是指示方法的。

    public String add(){
        BookService bookService = new BookServiceImpl();
        try{

            bookService.add(book);
            return ActionResultConst.SUCCESS;
        }catch (Exception e){
            return ActionResultConst.FAIL;
        }
    }

    public String list(){
        BookService bookService = new BookServiceImpl();
        setBooks(bookService.getAll());
        return ActionResultConst.SUCCESS;
    }



}
